package com.thread.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveAction;

public class ForkJoinTest1 extends RecursiveAction {

    static int n = 100;

    @Override
    protected void compute() {
        if(n < 1){
            System.out.println(Thread.currentThread().getName() + " running...");
        }else{
            n--;
            ForkJoinTest1 test1 = new ForkJoinTest1();
            ForkJoinTest1 test2 = new ForkJoinTest1();
            test1.fork();
            test2.fork();
            test1.isCompletedAbnormally();
            test1.getException();
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ForkJoinTest1 test1 = new ForkJoinTest1();
        ForkJoinPool forkJoinPool = new ForkJoinPool(4);
        ForkJoinTask<Void> result = forkJoinPool.submit(test1);
        System.out.println(result.get());
        Runtime.getRuntime().availableProcessors();

    }
}
